package br.com.vti.sisp_sicrim.antigo.controller.relatorios;

import java.io.FileNotFoundException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import net.sf.jasperreports.engine.JRException;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.interceptor.download.InputStreamDownload;
import br.com.vti.sisp_sicrim.antigo.model.SicTabelas;
import br.com.vti.sisp_sicrim.antigo.util.Relatorios;
import br.com.vti.sisp_sicrim.antigo.util.Sessao;

/**
 * Classe responsavel por encapsular o tratamento e as consistencias da tela
 * Tabpee01Report
 * 
 * @author Incode - Data: mai/2014
 * 
 */
public class Tabpee01Report {
	private String nomeClasse;
	private int dataCorrente;
	private Long dintabCodele; // DB
	private String diatabChalfa; // DB
	private String diatabDescel; // DB
	private String nroPagina;
	private String horaCorrente;
	private Result result;
	private Sessao sessao;
	private Relatorios report;
	// Classes views
	SicTabelas vwDvetab = new SicTabelas();
	SicTabelas vwTabele = new SicTabelas(); // Classes includes

	public Tabpee01Report() throws JRException {
		inicializar();
	}

	public Tabpee01Report(Sessao sessao) throws JRException {
		this.sessao = sessao;
		inicializar();
	}

	public void inicializar() throws JRException {
		report = new Relatorios();
		nomeClasse = this.getClass().getSimpleName();
		dataCorrente = 0;
		horaCorrente = new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()); // *TIMX
		report.setNumeroRel(1, "C");
		{
			report.setNumeroLinhaRel(1, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", " ");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(2, 3);
			{
				report.adicionaCampo(1, 60, "lit_1_60", "C", "", "GEJUSPC/GEPLAN/STI - SISP                     PROG: TABPEE01");
				report.adicionaCampo(65, 9, "lit_65_9", "C", "", "PAG:     ");
				report.adicionaCampo(75, 5, "nroPagina", "S", "ZZZZZ9", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(3, 3);
			{
				report.adicionaCampo(1, 48, "lit_1_48", "C", "", "TABELA DOS MUNICIPIOS DO BRASIL                 ");
				report.adicionaCampo(65, 4, "lit_65_4", "C", "", "DAT:");
				report.adicionaCampo(70, 8, "dataCorrente", "N", "99/99/9999", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(4, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(5, 4);
			{
				report.adicionaCampo(1, 11, "lit_1_11", "C", "", "COD.MUNICIP");
				report.adicionaCampo(15, 9, "lit_15_9", "C", "", "FEDERACAO");
				report.adicionaCampo(32, 17, "lit_32_17", "C", "", "NOME DO MUNICIPIO");
				report.adicionaCampo(62, 5, "lit_62_5", "C", "", "C E P");
				report.setFimLinhaRel();
			}
		}
		report.setNumeroRel(2, "D");
		{
			report.setNumeroLinhaRel(1, 3);
			{
				report.adicionaCampo(1, 12, "Dintabcodele", "N", "", "");
				report.adicionaCampo(15, 14, "Diatabchalfa", "X", "", "");
				report.adicionaCampo(32, 60, "Diatabdescel", "X", "", "");
				report.setFimLinhaRel();
			}
		}
	}

	public boolean validar() {
		return true;
	}

	public String getNomeClasse() {
		return nomeClasse;
	}

	public void setNomeClasse(String nomeClasse) throws ParseException {
		this.nomeClasse = nomeClasse;
		report.adicionaValorReport("Program", nomeClasse);
	}

	public int getDataCorrente() {
		return dataCorrente;
	}

	public void setDataCorrente(int dataCorrente) throws ParseException {
		this.dataCorrente = dataCorrente;
		report.adicionaValorReport("dataCorrente", dataCorrente);
	}

	public String getNroPagina() {
		return nroPagina;
	}

	public void setNroPagina(String nroPagina) throws ParseException {
		this.nroPagina = nroPagina;
		report.adicionaValorReport("nroPagina", nroPagina);
	}

	public String getHoraCorrente() {
		return horaCorrente;
	}

	public void setHoraCorrente(String horaCorrente) throws ParseException {
		this.horaCorrente = horaCorrente;
		report.adicionaValorReport("horaCorrente", horaCorrente);
	}

	public void setPageSize(int pagesize) throws JRException {
		report.setPageSize(pagesize);
	}

	public void setLineSize(int linesize) {
		report.setLineSize(linesize);
	}

	public int getPageSize() {
		return report.getPageSize();
	}

	public int getPageLine() {
		return report.getPageLine();
	}

	public void saltaLinhas(int qtdLinhas) throws ParseException, JRException {
		report.saltaLinhas(qtdLinhas);
	}

	public void gravaRelatorio(int nroRel) throws ParseException, JRException {
		setNroPagina(String.valueOf(report.getPageNumber()));
		report.gravaRelatorio(report, nroRel, false);
	}

	public InputStreamDownload imprimir() throws FileNotFoundException, JRException {
		return report.imprimir();
	}

	public Long getDintabCodele() {
		return dintabCodele;
	}

	public void setDintabCodele(Long dintabCodele) throws ParseException {
		this.dintabCodele = dintabCodele;
		report.adicionaValorReport("dintabCodele", dintabCodele);
	}

	public String getDiatabChalfa() {
		return diatabChalfa;
	}

	public void setDiatabChalfa(String diatabChalfa) throws ParseException {
		this.diatabChalfa = diatabChalfa;
		report.adicionaValorReport("diatabChalfa", diatabChalfa);
	}

	public String getDiatabDescel() {
		return diatabDescel;
	}

	public void setDiatabDescel(String diatabDescel) throws ParseException {
		this.diatabDescel = diatabDescel;
		report.adicionaValorReport("diatabDescel", diatabDescel);
	}

}
